/*
 * Created on Feb 23, 2004
 *
 * Author: Sandeep Prakash
 * Project: Sucxentv2 (using leaf nodes only)
 */
package dbsucxentW.storageEdgeW.entitiesW;

import java.util.*;

import dbsucxentW.storageEdgeW.loadersW.Store;
;

/**
 * @author Administrator
 *
 * 
 */
public abstract class PathCollection {

	protected Hashtable _paths;
	protected Enumeration _keys;
	
	protected int _maxId = 0;
	protected int _updateId = 0;
	
	public PathCollection() {
		super();
		_paths = new Hashtable(10000);
		_maxId = 0;
		_updateId = 0;
	}
	
	public int getPathId(String path, Store _store) {
	//	Launcher.getLoggerInstance().error( "maxId" + _maxId);
		if( _paths.containsKey( path ) ){
			return ( ( Integer )_paths.get( path )).intValue() ;
		}else{
		    _maxId++;
			_paths.put( path, new Integer( _maxId ) );
			
			_store.storePath(_maxId, path);
			//Launcher.getLoggerInstance().info(_paths.size() + "paths" + path);
			return _maxId;
		}
	}
	
	public abstract void loadPaths();
	
	public boolean hasMorePaths(){
		
		if( _keys == null ){
			_keys = _paths.keys();
		}
		
		return _keys.hasMoreElements();
	}
	
	public String newPath(){
		
		if( _keys == null ){
			return null;
		}
		
		String path = _keys.nextElement().toString();
		int pathId = ( ( Integer )_paths.get( path )).intValue() ;
		
		while( pathId <= _updateId && _keys.hasMoreElements() ){
			path = _keys.nextElement().toString();
			pathId = ( ( Integer )_paths.get( path )).intValue() ;
		}
		
		if( pathId > _updateId ){
			return path;
		}else{
			return null;
		}
	}
}
